package cn.edu.scau.cmi.zhangxiyang.client;

import cn.edu.scau.cmi.zhangxiyang.Adapter.*;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class AdapterClient extends Application{
public void start(Stage primaryStage) {
		
		Stage stage = new Stage();
		BorderPane border = new BorderPane();
		GridPane gp = new GridPane();
		border.setCenter(gp);
		TextArea text = new TextArea();
		border.setBottom(text);
		
		gp.setHgap(10);
		gp.setVgap(10);
		gp.setPadding(new Insets(0, 10, 0, 10));
		
		Label label5 = new Label("请选择地区：");
		gp.add(label5, 1, 1);
		
		ComboBox combobox = new ComboBox();
		combobox.getItems().addAll("美国","中国");
		gp.add(combobox, 2, 1);
		
		Button btn = new Button("充电");
		gp.add(btn, 1, 2);
		
		btn.setOnAction(e -> {  
			if(combobox.getValue() != null) {
				Target a = null;
				if(combobox.getValue() == "美国") {
					a = new AdapterOfClass();
					text.setText(a.Charge());
					System.out.println(a.Charge());
				}
				else {
					a = new AdapterOfObject();
					text.setText(a.Charge());
					System.out.println(a.Charge());
				}
			}
        });
		
	
		
		stage.setScene(new Scene(border,350,350));
		stage.setTitle("适配器模式");
        stage.show();
	}
	
	public static void main(String args[]) {

		launch(args);
	}

}
